<?php

session_start();
require('../../functions/settings.php');
$conn = mysql_connect( $dbHost, $dbUser, $dbPass ) or die("unable to connect to Database");
mysql_select_db($dbName);

if(isset($_SESSION['admin_user'])){

// featured image

$sql= "SELECT featured_photo FROM galleries WHERE id = '".$_GET['gallery_id']."'";
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
$rs = mysql_fetch_assoc($query);

$featured_photo = $rs['featured_photo'];

// limit
$limit = 'LIMIT '.(($_GET['page_id'] - 1) * 32).', 32';

$sql = "SELECT id, image FROM photos WHERE gallery_id = '".mysql_real_escape_string($_GET['gallery_id'])."'".$limit;
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

$i = 1;

while($rs = mysql_fetch_assoc($query)){

	$margin = (is_int($i / 8)) ? ' style="margin-right: 0;"' : '' ;
	
	$featured = ($featured_photo == $rs['id']) ? '1' : '0' ;
	
	echo '<div class="image_wrapper"'.$margin.'>
	<a onclick="$.prettyPhoto.open(\'/images/uploads/large/'.$rs['image'].'\',\'\',\'\');"><img src="/images/uploads/thumbs/'.$rs['image'].'" alt="" width="76" /></a>
	<a href="?id='.$_GET['gallery_id'].'&amp;delete='.$rs['id'].'&amp;page='.$_GET['page_id'].'" class="delete_image">Delete</a>
	<a href="?id='.$_GET['gallery_id'].'&amp;set_featured='.$rs['id'].'&amp;page='.$_GET['page_id'].'" title="Featured" class="featured_image"><img src="images/'.$featured.'.png" alt="" /></a>
	<span>'.$rs['id'].'</span>
	</div>';

$i++;
	
}

}

?>